package top.hidoctor.auscultation.utils;

import android.util.Log;

import com.tang.util.GsonUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import top.hidoctor.auscultation.bean.AreaBean;
import top.hidoctor.auscultation.bean.ProblemBean;
import top.hidoctor.auscultation.widget.tree.TypeBeanString;

public class LabelUtils {

    /**
     * 获取 五大分区 时间段
     *
     * @param data
     * @return
     */
    public static int[] getSectionStartAndEnd(String data) {
        int[] ints = new int[2];
        try {
            List<AreaBean> list = new ArrayList<>();
            JSONObject jo = new JSONObject(data);
            JSONArray names = jo.names();
            for (int i = 0; i < names.length(); i++) {
                String string = jo.getString(names.get(i).toString());
                AreaBean areaBean = GsonUtil.parseJson(string, AreaBean.class);
                list.add(areaBean);
            }
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getType() == 1) {
                    ints[0] = list.get(i).getBegin();
                    ints[1] = list.get(i).getEnd();
                    return ints;
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ints;
    }



    //sp数据 10000个点为一组进行绘制
    public static List groupList(List list) {
        List<List<Integer>> lists = new ArrayList<>();
        int listSize = list.size();
        int toIndex = 10000;
        for (int i = 0; i < list.size(); i += 10000) {
            if (i + 10000 > listSize) {
                toIndex = listSize - i;
            }
            List newList = list.subList(i, i + toIndex);
            lists.add(newList);
        }
        return lists;
    }
}
